package com.xcdh.trading.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xcdh.commons.controller.BaseController;
import com.xcdh.domain.vo.R;
import com.xcdh.trading.entity.AStock;
import com.xcdh.trading.entity.StockInfo;
import com.xcdh.trading.service.AStockService;
import com.xcdh.trading.service.DayTransactionDataService;
import com.xcdh.trading.service.StockInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/stock-info")
public class AStockController extends BaseController<AStock ,AStockService > {

    @Autowired
    private AStockService aStockService;

    @Autowired
    private StockInfoService stockInfoService ;

    @Autowired
    private DayTransactionDataService dayTransactionDataService ;

    // 查询所有股票信息
    @GetMapping("/list")
    public List<AStock> list() {
        return aStockService.list();
    }

    @PostMapping("/downLoadAStock/{dateCode}")
    public R syncTransactionData(@PathVariable String dateCode){
        dayTransactionDataService.syncTransactionData(dateCode);
        dayTransactionDataService.countTransactionData(dateCode);
        return R.ok();
    }

    @PostMapping("/syncAstock/{dateCode}")
    public R syncAstock(@PathVariable String dateCode){
        aStockService.syncAstock();
        return R.ok();
    }

    @PostMapping("/newTradeDate")
    public R<Map<String,String>> newTradeDate(){
        String tradeDate = stockInfoService.selectMaxTradeDate();
        Map<String,String> result = new HashMap<>() ;
        result.put("tradeDate" , tradeDate) ;
        result.put("tradeDateCode" , tradeDate.replaceAll("-" , "")) ;
        return R.okData(result) ;
    }
}
